﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace sXNAke
{
    class Snake : GameObject
    {
        
        private uint player;

        private enum Direction {LEFT,RIGHT, UP, DOWN}
        Direction actual_direction = Direction.RIGHT;

        private int points;

        private int lifes;
        

        public Snake(Texture2D texture, GameWindow Window, uint player)
        {
            this.texture = texture;
            this.Window = Window;
            this.player = player;
            this.points = 0;
            this.lifes = 5;
            Velocity = new Vector2(6,6);
        }

        public override void Update()
        {
            
        }

        public void Update(KeyboardState keyboardState)
        {
            if (player == 1)
            {
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    if (actual_direction != Direction.LEFT)
                        actual_direction = Direction.RIGHT;
                    //position.X += 5;
                }
                else
                    if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        if (actual_direction != Direction.RIGHT)
                            actual_direction = Direction.LEFT;
                        //position.X -= 5;
                    }
                    else
                        if (keyboardState.IsKeyDown(Keys.Down))
                        {
                            if (actual_direction != Direction.UP)
                                actual_direction = Direction.DOWN;
                            //position.Y += 5;
                        }
                        else
                            if (keyboardState.IsKeyDown(Keys.Up))
                            {
                                if (actual_direction != Direction.DOWN)
                                    actual_direction = Direction.UP;
                                //position.Y -= 5;
                            }
            }
            else
            {
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    if (actual_direction != Direction.LEFT)
                        actual_direction = Direction.RIGHT;
                    //position.X += 5;
                }
                else
                    if (keyboardState.IsKeyDown(Keys.A))
                    {
                        if (actual_direction != Direction.RIGHT)
                            actual_direction = Direction.LEFT;
                        //position.X -= 5;
                    }
                    else
                        if (keyboardState.IsKeyDown(Keys.S))
                        {
                            if (actual_direction != Direction.UP)
                                actual_direction = Direction.DOWN;
                            //position.Y += 5;
                        }
                        else
                            if (keyboardState.IsKeyDown(Keys.W))
                            {
                                if (actual_direction != Direction.DOWN)
                                    actual_direction = Direction.UP;
                                //position.Y -= 5;
                            }
            }

            if (position.X >= Window.ClientBounds.Width - texture.Width)
            {
                position.X = Window.ClientBounds.Width - texture.Width;
            }
            if (position.X <= 0)
            {
                position.X = 0;
            }
            if (position.Y <= 0)
            {
                position.Y = 0;
            }
            if (position.Y >= Window.ClientBounds.Height - texture.Height)
            {
                position.Y = Window.ClientBounds.Height - texture.Height;
            }
           
            switch (actual_direction)
            {
                case (Direction.LEFT):
                    position.X -= Velocity.X;
                    break;
                case (Direction.RIGHT):
                    position.X += Velocity.X;
                    break;
                case (Direction.UP):
                    position.Y -= Velocity.Y;
                    break;
                case (Direction.DOWN):
                    position.Y += Velocity.Y;
                    break;
            }
            //collisionRect = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);

        }

       
    }
}
